function submitComment() {
    let comment = $("form[id='commentForm']").serializeArray();
    comment = formatToObject(comment)
    let articleSeq = $("#commentForm").attr("data");
    comment.referenceId = articleSeq;
    console.log(comment)
    console.log(articleSeq)
    if (validComment(comment)) {
        request({
            url: baseUrl + "/api/comment",
            method: 'post',
            data : comment
        }).then((response) => {
            if (response && response.code === 200) {
                appendCommentForUI(comment)
            }
        }).catch(function (error) {
            console.log(error);
        });
    }

}

function validComment(comment) {
    return true;
}

function formatToObject(comment) {
    let result = {};
    for (let object of comment) {
        result[object.name] = object.value;
    }
    return result;
}

function appendCommentForUI(comment) {
    console.log(comment)
    let container = $("#commentContainer")
    let now = new Date();
    let htmlContent = `<div class="single-comment">
                <span class="reply-btn"><a href="#">回复</a></span>
                <div class="image">
                    <img src="/index/images/blog-image/comment-icon.png" alt="">
                </div>
                <div class="content">
                    <h3 class="user">admin <span class="comment-time">${now}</span></h3>
                    <p class="comment-text">${comment.message}</p>
                </div>
            </div>`;
    container.append(htmlContent);
}